package com.xiaoxiong.text;

import java.util.Calendar;
import java.util.TimeZone;

import android.annotation.SuppressLint;
import android.os.Handler;
import android.os.Message;
import android.widget.TextView;

public class DateThread extends Thread {
	private TextView tv_week;
	private String mWay;
	private Calendar c;

	public DateThread(TextView tv_week) {
		super();
		this.tv_week = tv_week;
		c = Calendar.getInstance();
		c.setTimeZone(TimeZone.getTimeZone("GMT+8:00"));
	}

	@SuppressLint("HandlerLeak")
	Handler handler = new Handler() {
		
		@Override
		public void handleMessage(Message msg) {
			if (msg.what == 1) {
				mWay = String.valueOf(c.get(Calendar.DAY_OF_WEEK));
				if ("2".equals(mWay)) {
					mWay = "周一";
				} else if ("3".equals(mWay)) {
					mWay = "周二";
				} else if ("4".equals(mWay)) {
					mWay = "周三";
				} else if ("5".equals(mWay)) {
					mWay = "周四";
				} else if ("6".equals(mWay)) {
					mWay = "周五";
				} else if ("7".equals(mWay)) {
					mWay = "周六";
				} else if ("1".equals(mWay)) {
					mWay = "周日";
				}
				tv_week.setText(mWay);
			}
		};
	};

	@Override
	public void run() {
		super.run();
		while (true) {
			try {
				Thread.sleep(1000);
				Message msg = new Message();
				msg.what = 1;
				handler.sendMessage(msg);
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
	}
}
